/* 测试 */

const {
    uPutToken
} = require('../core/utils')
const Mail = require('../core/Mail')

class TestController {
    async usePutToken(ctx) {
        const uid = 111111
        const token = uPutToken(uid)
        ctx.body = token
    }

    async useRes(ctx) {
        // new Response(ctx)

        global.Response.fail(ctx)

        let err = '错误'
        // if (!err) {
        //     ctx.body = global.res.success({
        //         data
        //     })

        // } else {
        //     ctx.status = 404
        //      ctx.body = global.res.fail({
        //          msg: err
        //      })
        // }
    }

    async sendMailCode(ctx) {
        const {email} = ctx.request.body

        let code = Mail.sendCode(email)
        code = global.utils.uMd5(code)
        global.Response.success(ctx, undefined, {email,code})
    }

    async sendMail(ctx) {
        const {
            email,
            content
        } = ctx.request.body
        Mail.sendEmail(email, content || '消息已发送，请等待博主回复~')
        global.Response.success(ctx, undefined, {
            email,
            content
        })
    }

}

module.exports = new TestController